package com.hd123.rumba.gwt.widget2.client.form;

import com.google.gwt.user.client.ui.Widget;
import com.hd123.rumba.gwt.widget2.client.fielddef.FieldDef;

/**
 * 基于数据字典的验证器
 * 
 * @author LiQi
 * 
 */
public class RValidatorOnFieldDef implements RValidator {

  /** 数据字典项 */
  private FieldDef fieldDef;

  /**
   * @param fieldDef
   *          数据字典项
   */
  public RValidatorOnFieldDef(FieldDef fieldDef) {
    this.fieldDef = fieldDef;
  }

  public ValidResult validate(Widget sender, String value) {
    StringBuffer message = new StringBuffer();
    boolean valid = fieldDef == null ? true : fieldDef.validateText(value, message);
    return valid ? ValidResult.info(message.toString()) : ValidResult.error(message.toString());
  }

}
